import os
import time 
from items import progress_bar

# 文件导出地址目前是写死的，之后会更改成用户自行选择导出 
# 之后会更改为可以由用户选择导出的图片id，目前是导出全部图片



def export(data_list):
   
    try:
        print("start  progress...".center(len(data_list) // 2,"-"))

        if not os.path.isdir(os.getcwd() + r"/export_picture"):
            os.mkdir(os.getcwd() + r"/export_picture/")

        for i in range(len(data_list)):
            progress_bar.progress_bar_start(len(data_list), i)

            file_object = data_list[i]["file_object"]
            file_name = "./export_picture/" + data_list[i]["picture_name"] + "." + data_list[i]["picture_format"]
            open(file_name, 'wb').write(file_object)
            
        progress_bar.progress_bar_end(len(data_list))
    
    except Exception as ex:
        print("export picture failed :" + str(ex))
        
    


        
